import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

// 路由报错解析
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)

}
const routes = [
  {
    path: '/',
    name: 'Index',
    component: () => import(/* webpackChunkName: "Index" */ '@/views/index'), //首页(待交互)
    meta: {
      keep: true,
    }
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import(/* webpackChunkName: "Index" */ '@/views/login'), //登录(待交互)
    meta: {
      keep: true,
    }
  },
  {
    path: '/service',
    name: 'Service',
    component: () => import(/* webpackChunkName: "Index" */ '@/views/service'), //登录(待交互)
    meta: {
      keep: true,
    }
  },
  {
    path: '/personal',
    name: 'Personal',
    component: () => import(/* webpackChunkName: "Index" */ '@/views/personal'), //登录(待交互)
    meta: {
      keep: true,
    }
  },
  {
    path: '/personal/set',
    name: 'Set',
    component: () => import(/* webpackChunkName: "Index" */ '@/views/personal/set'), //登录(待交互)
  },
  {
    path: '/personal/help',
    name: 'Help',
    component: () => import(/* webpackChunkName: "Index" */ '@/views/personal/help'), //登录(待交互)
  },
  {
    path: '/personal/balance',
    name: 'Balance',
    component: () => import(/* webpackChunkName: "Index" */ '@/views/personal/balance'), //登录(待交互)
  },{
    path: '/process',
    name: 'Process',
    component: () => import(/* webpackChunkName: "Index" */ '@/views/process/index'), //登录(待交互)
    meta: {
      keep: true,
    }
  },{
    path: '/process/bank',
    name: 'Bank',
    component: () => import(/* webpackChunkName: "Index" */ '@/views/process/bank'), //登录(待交互)
  },{
    path: '/vip',
    name: 'Vip',
    component: () => import(/* webpackChunkName: "Index" */ '@/views/vip'), //登录(待交互)
  },
  {
    path: '/register/:uniqid',
    name: 'Register',
    component: () => import(/* webpackChunkName: "Index" */ '@/views/register'), //注册(待交互)
  }
]

const router = new VueRouter({
  routes,
  scrollBehavior(to, from, savedPosition) {  //切换页面滚动
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  }
})

export default router
